﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace Software_2Project.DB_Layer
{
    class DB_Deposite
    {
        public string ConString =
           "Data Source=crespooo;Initial Catalog=ATM;Integrated Security=True;MultipleActiveResultSets=true";
        SqlConnection con = new SqlConnection();

        DataTable dt = new DataTable();
        //public int acconum;
        //public int balance;
        public int dbbalance;
     

            public DataTable deposite(Int32 acconum,Int32 balance)
            {
                con.ConnectionString = ConString;
                try
                {
                    if (ConnectionState.Closed == con.State)
                        con.Open();
                    SqlCommand cmd = new SqlCommand("SELECT balance FROM bank where acconum = " + acconum + " ", con);
                    SqlDataReader rd = cmd.ExecuteReader();
                    rd.Read();
                    dbbalance = Convert.ToInt32(rd["balance"]);



                    SqlCommand cmd1 = new SqlCommand("UPDATE bank  SET balance = " + dbbalance + " +  " + balance + " WHERE acconum = " + acconum + " ", con);
                    SqlDataReader rd1 = cmd1.ExecuteReader();

                    SqlCommand cmmd = new SqlCommand("SELECT acconum,password FROM bank ", con);
                    SqlDataReader rd2 = cmmd.ExecuteReader();
                    dt.Load(rd2);
                
                    con.Close();
                    return dt;
                

                }

                catch//(SqlException es)
                {
                     //return es.Message;
                    con.Close();
                    throw;
                }
           
            }
        
    }
}
